package com.ycz.config;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author ycz
 * @date 2021/6/11
 * @description TODO
 *
 */
@Configuration
public class RabbitConnectionUtil {
    // http://47.107.245.27:15672/
    static String host = "47.107.245.27";
    static String name = "admin";
    static String password = "admin";
    static Integer port = 5672;


    public static Connection getRabbitConnection() {
        try {
            Connection connection = null;
            //定义一个连接工厂
            ConnectionFactory factory = new ConnectionFactory();
            //设置服务端地址（域名地址/ip）
            factory.setHost(host);
            //设置服务器端口号
            factory.setPort(port);
            //设置虚拟主机(相当于数据库中的库)
            factory.setVirtualHost("/");
            //设置用户名
            factory.setUsername(name);
            //设置密码
            factory.setPassword(password);
            connection = factory.newConnection();
            return connection;
        } catch (Exception e) {
            return null;
        }
    }

}
